package com.ruoyi.buss.grade.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.buss.grade.domain.DataCustGradeInfo;
import com.ruoyi.buss.grade.service.IDataCustGradeInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 个人维度表Controller
 * 
 * @author sxy
 * @date 2022-04-25
 */
@RestController
@RequestMapping("/dataCustGradeInfo")
public class DataCustGradeInfoController extends BaseController
{
    @Autowired
    private IDataCustGradeInfoService dataCustGradeInfoService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询个人维度表列表
     */
    @PreAuthorize(hasPermi = "DataCustGradeInfo:dataCustGradeInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(DataCustGradeInfo dataCustGradeInfo)
    {
        startPage();
        List<DataCustGradeInfo> list = dataCustGradeInfoService.selectDataCustGradeInfoList(dataCustGradeInfo);
        return getDataTable(list);
    }

    /**
     * 导出个人维度表列表
     */
    @PreAuthorize(hasPermi = "DataCustGradeInfo:dataCustGradeInfo:export")
    @Log(title = "个人维度表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataCustGradeInfo dataCustGradeInfo) throws IOException
    {
        List<DataCustGradeInfo> list = dataCustGradeInfoService.selectDataCustGradeInfoList(dataCustGradeInfo);
        ExcelUtil<DataCustGradeInfo> util = new ExcelUtil<DataCustGradeInfo>(DataCustGradeInfo.class);
        util.exportExcel(response, list, "个人维度表数据");
    }

    /**
     * 获取个人维度表详细信息
     */
    @PreAuthorize(hasPermi = "DataCustGradeInfo:dataCustGradeInfo:query")
    @GetMapping(value = "/{idCard}")
    public AjaxResult getInfo(@PathVariable("idCard") String idCard)
    {
        return AjaxResult.success(dataCustGradeInfoService.selectDataCustGradeInfoById(idCard));
    }

    /**
     * 新增个人维度表
     */
    @PreAuthorize(hasPermi = "DataCustGradeInfo:dataCustGradeInfo:add")
    @Log(title = "个人维度表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataCustGradeInfo dataCustGradeInfo)
    {
        return toAjax(dataCustGradeInfoService.insertDataCustGradeInfo(dataCustGradeInfo));
    }

    /**
     * 修改个人维度表
     */
    @PreAuthorize(hasPermi = "DataCustGradeInfo:dataCustGradeInfo:edit")
    @Log(title = "个人维度表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataCustGradeInfo dataCustGradeInfo)
    {
        return toAjax(dataCustGradeInfoService.updateDataCustGradeInfo(dataCustGradeInfo));
    }

    /**
     * 删除个人维度表
     */
    @PreAuthorize(hasPermi = "DataCustGradeInfo:dataCustGradeInfo:remove")
    @Log(title = "个人维度表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{idCards}")
    public AjaxResult remove(@PathVariable String[] idCards)
    {
        return toAjax(dataCustGradeInfoService.deleteDataCustGradeInfoByIds(idCards));
    }

    /**
     * 根据条件获取当前方案客户数
     */
    @PreAuthorize(hasPermi = "DataCustGradeInfo:dataCustGradeInfo:count")
    @PostMapping("/count")
    public AjaxResult count(@RequestBody DataCustGradeInfo dataCustGradeInfo)
    {
        return AjaxResult.success(dataCustGradeInfoService.selectDataCustGradeInfoCount(dataCustGradeInfo));
    }

    /**
     * 根据条件生成支行营销任务
     */
    @PreAuthorize(hasPermi = "DataCustGradeInfo:dataCustGradeInfo:InsertTask")
    @PostMapping("/insertTask")
    public AjaxResult insertTask(@RequestBody DataCustGradeInfo dataCustGradeInfo)
    {
        LoginUser userInfo = tokenService.getLoginUser();
        return AjaxResult.success(dataCustGradeInfoService.insertTask(dataCustGradeInfo, userInfo));
    }
}
